﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Yunzuan.Foundation.DataAccess;
using Yunzuan.Foundation.Entities;
using Yunzuan.Foundation.Web;

namespace CloudDiamonds.Models.Manager
{
    public class PageParamOfInventory1 : IPageParam
    {
        private int pageIndex;
        private int pageSize;

        public int PageSize
        {
            get
            {
                return pageSize;
            }
            set
            {
                this.pageSize = value;
            }
        }

        public int PageIndex
        {
            get
            {
                return pageIndex;
            }
            set
            {
                this.pageIndex = value;
            }
        }

        public int PageCount { get; set; }

        public string[] Shape { get; set; }
        private string[] _color;
        public string[] Color
        {
            get
            {

                //if (_color == null)
                //{
                //    if (IntensityParam != null && OvertoneParam != null)
                //    {
                //        _color = new string[IntensityParam.Length + OvertoneParam.Length];
                //        IntensityParam.CopyTo(this._color, 0);
                //        OvertoneParam.CopyTo(this._color, IntensityParam.Length);
                //    }
                //    else if (IntensityParam != null)
                //    {
                //        _color = new string[IntensityParam.Length];
                //        IntensityParam.CopyTo(this._color, 0);
                //    }
                //    else if (OvertoneParam != null)
                //    {
                //        _color = new string[OvertoneParam.Length];
                //        OvertoneParam.CopyTo(this._color, 0);
                //    }

                //}
                return this._color;
            }
            set
            {
                this._color = value;
            }
        }
        public string[] Clarity { get; set; }
        public string[] Cut { get; set; }
        public string[] Polish { get; set; }
        public string[] Symmetry { get; set; }
        public string[] Fluorescence { get; set; }

        public string[] CertType { get; set; }
        
        private string _CertNo;
        public string CertNo { get { if (_CertNo == "") return null; return _CertNo; } set { _CertNo = value; } }
        private string[] _milky;
        public string[] Milky
        {
            get
            {
                return MilkysHues;
            }
            set 
            {
                this._milky = value;
            }
        }
        private string[] _hue;
        public string[] Hue
        {
            get
            {
                return MilkysHues;
            }
            set 
            {
                this._hue = value;
            }
        }
        public string[] Address { get; set; }
        public float WeightMin { get; set; }
        public float WeightMax { get; set; }
        private string _SN;
        public string SN { get { if (_SN == "") return null; return _SN; } set { _SN = value; } }
        public int UserID { get; set; }
        public string SortColumn { get; set; }
        public string SortDirect { get; set; }

       
        public int CustomerID { get; set; }
        public string[] Place { get; set; }
        public int? IsFancy { get; set; }
        public string IntensitySQL { get; set; }
        public string OvertoneSQL { get; set; }
  
        public string[] MilkysHues { get; set; }
        public string IntensityMHSQL { get; set; }
        public readonly bool useDict = true;
        /// <summary>
        /// 现货：0.否，1.是
        /// </summary>
        public int Stock { get; set; }
        public string[] GoodsStatus { get; set; }

        //数据仓库的数据类型为[]
        private string[] weight;
        public string[] Weight
        {
            get
            {
                if (WeightMax > 0) this.weight = new string[] { WeightMin.ToString(), WeightMax.ToString() };
                else this.weight = null;

                return weight;
            }
            set
            {
                this.weight = value;
            }
        }
        //数据仓库的数据类型为[]
        private string[] sort;
        public string[] Sort
        {
            get
            {
                if (SortColumn == null || SortDirect == null) this.sort = null;
                else this.sort = new string[] {SortColumn=="Weight"?"Weight":"OriginUSDPerGrain", SortDirect };  //仓库始终按总价排序,重量列外
                return sort;
            }
            set
            {
                this.sort = value;
            }
        }
        ////数据仓库的数据类型为[]
        //private string[] sns;
        //public string[] SNS
        //{
        //    get
        //    {
        //        if (SN == "") this.sns = null;
        //        else this.sns = new string[] { SN };
        //        return sns;
        //    }
        //    set
        //    {
        //        this.sns = value;
        //    }
        //}

        private string isTempFancy { get; set; }
        public string IsTempFancy
        {
            get
            {
                this.isTempFancy =  IsFancy.ToString();
                return isTempFancy;
            }
            set
            {
                this.isTempFancy = value;
            }
        }
        public string SupplierCode { get; set; }
        private string[] supplier { get; set; }
        public string[] Supplier
        {
            get
            {
                if (SupplierCode == "stock") 
                   this.supplier = CachePriorities();
                return supplier;
            }
            set
            {
                this.supplier = value;
            }
        }
        //现货供应商（排序使用）
        //private string[] priorities;
        //public string[] Supplier { get; set; }
        //{
        //    get
        //    {

        //        //得到当前系统的现货供应商 ,测试用,*******************************
        //        this.priorities = CachePriorities();
        //        return priorities;
        //    }
        //    set { this.priorities = value; }
        //}

        public string[] CachePriorities()
        {
            if (HttpRuntime.Cache.Get("Priorities") == null)
            {
                //get string[] 
                string[] strArray = GetSupplierCodeList();
                HttpRuntime.Cache.Insert("Priorities", strArray, null, DateTime.Now.AddSeconds(GlobalConfig.ExpirationTimeOut), TimeSpan.Zero);
                return strArray;

            }
            else
                return HttpRuntime.Cache.Get("Priorities") as string[];
        }
        //得到所有现货供应商 8-26
        public string[] GetSupplierCodeList()
        {
            IList<HashResult> list = YZ.Database.QueryForList<HashResult>("Supplier.GetSupplierCodeList", null);
            string[] codes = new string[list.Count];
            for (int i = 0; i < list.Count; i++)
            {
                codes[i] = list[i]["SupplierCode"].ToString();
            }
            return codes;
        }


        public string[] FancyStrength{get;set;}
        public string[] FancyColor { get; set; }
        public string WithinMinutes { get; set; }
        //自己拥有的货（此处指上传的） 
        public bool IsSelfStok { get; set; }
        public string SecondSN { get; set; }
        /// <summary>
        /// onlyCount: 是否只统计数量，注意：limit还是会生效的（当limit为1时，count不会大于1），默认：false
        /// </summary>
        public bool onlyCount { get; set; }




        //private Dictionary<string, string[]> _alias;
        public Dictionary<string, string[]> alias { get; set; }
        
        private Dictionary<string, string> _regexp;
        public Dictionary<string, string> regexp
        {
            get
            {
                Dictionary<string, string> dss = new Dictionary<string, string>();
                if (CertNo == null && SN == null) this._regexp = null;
                else
                {
                    if (CertNo != null)
                        dss.Add("CertNo", CertNo);
                    if (SN != null)
                        dss.Add("SN", SN); 
                    this._regexp = dss;
                }
                return _regexp;
            }
            set
            {
                this._regexp = value;
            }
        }
    }
}
